limsQualitycontrolplan.choosePage = {

    getGridParam: function () {
        var _this = this, columns = limsQualitycontrolplan.getChooseListColumns();
        return {
            type: 'grid',
            id: 'lims-qualitycontrolplan-choose-list-grid',
            url: limsQualitycontrolplan.baseUrl + '/queries/choosable',
            requestData: {
                activeStatus_EQ: 'on'
            },
            columns: columns,
            activateFirstRow: true,
            radio: true,
            page: true,
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    Gikam.getAsyncComp('lims-qualitycontrolplan-project-edit-list-grid').done(function (grid) {
                        grid.cleanData();
                    })
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('lims-qualitycontrolplan-project-edit-list-grid').done(function (grid) {
                    grid.refresh({
                        url: limsQualitycontrolplan.baseProjectUrl + '/queries',
                        requestData: {
                            planId_EQ: row.id
                        }
                    });
                })
            }
        }
    },

    getProjectGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-qualitycontrolplan-project-edit-list-grid',
            // url: limsQualitycontrolplan.baseProjectUrl + '/queries/raw',
            service: 'limsQualitycontrolplanProjectServiceImpl',
            dbTable: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT',
            columns: limsQualitycontrolplan.getProjectEditListColumns(),
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.CONFIRM',
                radio: true,
                icon: 'select',
                onClick: function () {
                    var data = {}
                    data.planRow = Gikam.getComp('lims-qualitycontrolplan-choose-list-grid').getActivedRow()
                    data.projectRows = Gikam.getComp('lims-qualitycontrolplan-project-edit-list-grid').getSelections()
                    Gikam.getLastModal().close(data);
                }
            }],
            onCellClick: function (field, row) {
                field === 'id' && _this.loadDetailPage(row.id);
            },
            page: true,
        }
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-qualitycontrolplan-choose-list-layout',
            renderTo: Gikam.getLastModal().window.$dom,
            north: {
                height: '50%', items: [_this.getGridParam()]
            },
            center: {
                items: [_this.getProjectGridParam()]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
};
